package cn.wetcland.es.service.impl;

import cn.wetcland.es.domain.EsStudent;
import cn.wetcland.es.dto.TeacherLoginDTO;
import cn.wetcland.es.utils.MyAssert;
import cn.wetcland.es.utils.bcrypt.BCryptPasswordEncoder;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.wetcland.es.domain.EsTeacher;
import cn.wetcland.es.service.EsTeacherService;
import cn.wetcland.es.mapper.EsTeacherMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

/**
* @author Wetcland
* @description 针对表【es_teacher】的数据库操作Service实现
* @createDate 2023-04-29 17:04:49
*/
@Service
public class EsTeacherServiceImpl extends ServiceImpl<EsTeacherMapper, EsTeacher> implements EsTeacherService{

    @Resource
    private EsTeacherMapper teacherMapper;

    @Override
    public void login(TeacherLoginDTO teacherLoginDTO, HttpSession session) {
        MyAssert.notBlank(teacherLoginDTO.getTeacherTno(), "教师工号不能为空");
        MyAssert.notBlank(teacherLoginDTO.getPassword(), "密码不能为空");
        EsTeacher teacher = teacherMapper.selectOne(new QueryWrapper<EsTeacher>().eq("es_teacher_tno", teacherLoginDTO.getTeacherTno()));
        MyAssert.notNull(teacher, "未查询到该工号的教师");
        BCryptPasswordEncoder passwordEncoder = new BCryptPasswordEncoder();
        MyAssert.isTrue(passwordEncoder.matches(teacherLoginDTO.getPassword(), teacher.getEsTeacherPassword()), "密码错误");
        session.setAttribute("roleName", "teacher");
        session.setAttribute("target", teacher);
    }
}




